<?php
function eval_buffer($string) 
{
    ob_start();
    eval("$string[2];");
    $ret = ob_get_contents();
    ob_end_clean();
    return $ret;
}

function eval_html($string) 
{
    return preg_replace_callback("/(<\?php|<\?)(.*?)\?>/si", "eval_buffer",$string);
} 


function smarty_eval($params) 
{ 
  if(!empty($params['code'])) 
  { 
    $content = $params['code']; 
    //execute php code if any
    $trans = array("&lt;?php" => "[php]", "?&gt;" => "[/php]");
	$content = strtr($content, $trans);
	
	$trans = array("<php>" => "<?php", "</php>" => "?>");
	$content = strtr($content, $trans);
	
	$content = html_entity_decode($content, ENT_QUOTES);
	$content = eval_html($content);
	
	$trans = array("[php]" => "&lt;?php", "[/php]" => "?&gt;");
	$content = strtr($content, $trans);
	
	return $content; 
  } 
} 

$smarty->register_function("smarty_eval", "smarty_eval"); 
?>